package com.expoents.springboot.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.expoents.springboot.config.RespPageBean;
import com.expoents.springboot.entity.Student;
import com.expoents.springboot.mapper.StudentMapper;
import com.expoents.springboot.service.IStudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author YXC
 * @since 2022-08-23
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {
  
  @Autowired
  private StudentMapper studentMapper;
  @Override
  public RespPageBean getStudentByPage(Integer currentPage, Integer size) {
    //开启分页
    Page<Student> page = new Page<>(currentPage,size);
    // IPage是国人开发的一个插件，用来做分页，可以点击去看源码（发现里面是中文的注释，因为是国人开发的）
    IPage<Student> stdentByPage = studentMapper.selectPage(page,null);
    RespPageBean respPageBean = new RespPageBean(stdentByPage.getTotal(), stdentByPage.getRecords());
    return respPageBean;
  }
}
